package com.letme.web.controller.appletApi;

import com.letme.common.core.controller.BaseController;
import com.letme.common.core.domain.AjaxResult;
import com.letme.store.domain.MallUserAddress;
import com.letme.store.service.IMallUserAddressService;
import com.letme.store.service.MallCitysService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * 用户地址管理
 *
 * @Description
 * @Author lock-xq
 * @Date 2025/9/12 11:27
 **/
@Tag(name = "小程序-地址管理")
@RestController
@RequestMapping("/applet/address")
public class UserAddressController extends BaseController {

    @Resource
    private MallCitysService mallCitysService;
    @Resource
    private IMallUserAddressService addressService;

    @Operation(summary ="根据父编号查询城市")
    @GetMapping("/queryCityByFatherCode")
    public AjaxResult queryCityByFatherCode(String fatherCode){
        return success(mallCitysService.queryCityList(fatherCode));
    }

    @Operation(summary ="查询城市树")
    @GetMapping("/queryCityTree")
    public AjaxResult queryCityTree(){
        return success(mallCitysService.cityTree());
    }


    @Operation(summary ="查询我的地址")
    @GetMapping("/queryMyAddress")
    public AjaxResult queryMyAddress(){
        return success(addressService.queryUserAddress());
    }

    @Operation(summary ="设置默认地址")
    @PostMapping("/setDefaultAddress")
    public AjaxResult setDefaultAddress(Long id){
        return success(addressService.updateAddressDefault(id));
    }

    @Operation(summary ="删除地址")
    @PostMapping("/deleteAddress")
    public AjaxResult deleteAddress(Long id){
        return success(addressService.fakeDelAddress(id));
    }

    @Operation(summary ="新增地址")
    @PostMapping("/addUserAddress")
    public AjaxResult addUserAddress(@RequestBody MallUserAddress address){
        return success(addressService.saveAddress(address));
    }


    @Operation(summary ="查询地址详情")
    @GetMapping("/queryAddressDetail")
    public AjaxResult queryAddressDetail(Long id){
        return success(addressService.queryAddressDetail(id));
    }

    @Operation(summary ="修改地址")
    @PostMapping("/modifyUserAddress")
    public AjaxResult modifyUserAddress(@RequestBody MallUserAddress address){
        return success(addressService.updateAddress(address));
    }



}
